﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;
using System.Xml;

namespace CommonUtility
{
    [Serializable]
    public class SystemConfig
    {
        /// <summary>
        /// Account
        /// </summary>
        public string Account { get; private set; }
        /// <summary>
        /// Email
        /// </summary>
        public string Email { get; private set; }
        /// <summary>
        /// SMTP
        /// </summary>
        public string SMTP { get; private set; }
        /// <summary>
        /// Password
        /// </summary>
        public string Password { get; private set; }
        /// <summary>
        /// 是否发送邮件
        /// </summary>
        public bool isSend { get; private set; }
        /// <summary>
        /// 系统路径
        /// </summary>
        public string Url { get; private set; }


        #region 构造
        public SystemConfig()
        {
            XElement xe = XElement.Load(System.AppDomain.CurrentDomain.BaseDirectory + "SystemConfig.xml");
            IEnumerable<XElement> elements = from ele in xe.Elements("EmailAccount") select ele;
            foreach (var ele in elements)
            {
                this.Account = ele.Element("Account").Value;
                this.Email = ele.Element("Email").Value;
                this.SMTP = ele.Element("SMTP").Value;
                this.Password = ele.Element("Password").Value;
                this.isSend = ele.Element("isSend").Value.Equals("1") ? true : false;
            }

            elements = from ele in xe.Elements("Url") select ele;
            foreach (var ele in elements)
                this.Url = ele.Value;

        }
        #endregion
    }
}
